//
//  JProductTextView.m
//  HeadIndustry
//
//  Created by jun on 2017/8/29.
//  Copyright © 2017年 jun. All rights reserved.
//

#import "JProductTextView.h"

@implementation JProductTextView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        [self setUpView];
        
    }
    return self;
}

- (void)setUpView
{
    _titleLabel = [YYLabel new];
    _titleLabel.top = 5;
    _titleLabel.left = 20;
    _titleLabel.size = CGSizeMake(kWindowW - 40, 40);
    _titleLabel.font = kFONT_TITLE(16);
    _titleLabel.textColor = [UIColor blackColor];
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    _titleLabel.numberOfLines = 0;
    [self addSubview:_titleLabel];
    
    _tagLabel = [YYLabel new];
    _tagLabel.top = _titleLabel.bottom;
    _tagLabel.left = 20;
    _tagLabel.size = CGSizeMake(kWindowW-40, 40);
    _tagLabel.font = kFONT_TITLE(14);
    _tagLabel.textColor = kRGBColor(78, 78, 78);
    _tagLabel.textAlignment = NSTextAlignmentCenter;
    _tagLabel.numberOfLines = 0;
    [self addSubview:_tagLabel];
    
    _oldPriceLabel = [YYLabel new];
    _oldPriceLabel.top = _tagLabel.bottom ;
    _oldPriceLabel.left = 20;
    _oldPriceLabel.size = CGSizeMake(kWindowW/2.0-5-20, 40);
    _oldPriceLabel.font = kFONT_TITLE(13);
    _oldPriceLabel.textColor = kRGBColor(78, 78, 78);
    _oldPriceLabel.textAlignment = NSTextAlignmentRight;
    [self addSubview:_oldPriceLabel];
    
    _lineLabel = [YYLabel new];
    _lineLabel.centerY = _oldPriceLabel.centerY;
    _lineLabel.right = _oldPriceLabel.right - _oldPriceLabel.width/3.5 ;
    _lineLabel.size = CGSizeMake(_oldPriceLabel.width/3.5, 1);
    _lineLabel.backgroundColor = kRGBColor(78, 78, 78);
    [self addSubview:_lineLabel];
    _lineLabel.hidden = YES;
    
    
    _nowPriceLabel = [YYLabel new];
    _nowPriceLabel.top = _tagLabel.bottom ;
    _nowPriceLabel.left = _oldPriceLabel.right+10;
    _nowPriceLabel.size = CGSizeMake(kWindowW/2.0-5-20, 40);
    _nowPriceLabel.font = kFONT_TITLE(20);
    _nowPriceLabel.textColor = [UIColor redColor];
    _nowPriceLabel.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_nowPriceLabel];
    
    _mouthNumberLabel = [YYLabel new];
    _mouthNumberLabel.top = _nowPriceLabel.bottom;
    _mouthNumberLabel.left = 20;
    _mouthNumberLabel.size = CGSizeMake(kWindowW-40, 30);
    _mouthNumberLabel.font = kFONT_TITLE(14);
    _mouthNumberLabel.textColor = kRGBColor(78, 78, 78);
    _mouthNumberLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_mouthNumberLabel];
}

- (void)setProductMedol:(JProductDetailModel *)productMedol
{
    _productMedol = productMedol;
    dispatch_async(dispatch_get_main_queue(), ^{
        _titleLabel.text = _productMedol.Name;
        _tagLabel.text = _productMedol.ShortDescription;
        _oldPriceLabel.text = _productMedol.OldPriceText;
        _nowPriceLabel.text = _productMedol.PriceText;
        _mouthNumberLabel.text = [NSString stringWithFormat:@"月销售%ld笔",(long)_productMedol.m_SalesCount];
        if (_oldPriceLabel.text.length > 0) {
            _lineLabel.hidden = NO;
        }
        else
        {
            _lineLabel.hidden = YES;
        }
    });
    
}

@end
